package org.robotlegs.demos.lazyfsm.views.mediators
{
	import org.robotlegs.core.IMediator;
	import org.robotlegs.demos.lazyfsm.events.ApplicationEvent;
	import org.robotlegs.demos.lazyfsm.views.components.MainView;
		import org.robotlegs.demos.lazyfsm.views.components.TheBrain;
	import org.robotlegs.mvcs.Mediator;

	public class LazyFSMMediator extends Mediator implements IMediator
	{
		[Inject]
		public var view:LazyFSM;
		
		public function LazyFSMMediator()
		{
		}
		
		override public function onRegister():void
		{
			view.messagesText.text="Application Mediator registered";
			addEventListenerTo(eventDispatcher, ApplicationEvent.CHANGE_MAINVIEW_STATE, handleChangeViewState);
			addEventListenerTo(eventDispatcher, ApplicationEvent.LOGG_MESSAGE, handleLoggMessage);
		}
		protected function handleChangeViewState(event:ApplicationEvent):void
		{
			mediatorFactory.mapMediator(MainView,MainViewMediator);
			mediatorFactory.mapMediator(TheBrain,TheBrainMediator);
			view.currentState=event.appMessage.toString();
		}
		protected function handleLoggMessage(event:ApplicationEvent):void
		{
			view.messagesText.text=event.appMessage+"";
		}
	}
}